package com.zbf.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zbf.common.SysInfo;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/6/4  11:53
 * 描述:
 */
public class MyContextUtils {

    /**
     * 作者: LCG
     * 日期: 2021/6/4  11:54
     * 描述: session中获取用户Id
     * @Param [request]
     * @Return java.lang.String
     */
    public static String getUserId(HttpServletRequest request){
        Object attribute = request.getSession().getAttribute(SysInfo.userInfo);
        JSONObject jsonObject = JSON.parseObject(attribute.toString());
        return jsonObject.get("id").toString();
    }


    /**
     * 作者: LCG
     * 日期: 2021/6/4  11:55
     * 描述: 获取用户信息
     * @Param [request]
     * @Return java.util.Map<java.lang.String,java.lang.Object>
     */
    public static Map<String,Object> getUserInfo(HttpServletRequest request){
        Object attribute = request.getSession().getAttribute(SysInfo.userInfo);
        Map<String,Object> map = JSON.parseObject(attribute.toString(), Map.class);
        return map;
    }

}
